package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.Replay;
import com.rabbiter.oes.result.R;
import com.rabbiter.oes.service.impl.ReplayServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "留言回复")
@RestController
public class ReplayController {

    @Autowired
    private ReplayServiceImpl replayService;

    @ApiOperation(value = "留言回复", notes = "留言回复", httpMethod = "POST")
    @PostMapping("/replay")
    public R add(@RequestBody Replay replay) {
        int data = replayService.add(replay);
        if (data != 0) {
            return R.ok("添加成功！").data(data);
        } else {
            return R.logicError("添加失败！");
        }
    }

    @ApiOperation(value = "根据留言id获取全部回复信息", notes = "根据留言id获取全部回复信息", httpMethod = "GET")
    @GetMapping("/replay/{messageId}")
    public R<List<Replay>> findAllByMessageId(@PathVariable("messageId") Integer messageId) {
        List<Replay> res = replayService.findAllByMessageId(messageId);
        return R.<List<Replay>>ok("根据messageId查询").data(res);
    }
}
